package com.jl.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jl.commons.constant.Constants;
import com.jl.commons.result.PageDataInfo;
import com.jl.mapper.DamagePartMapper;
import com.jl.model.DamagePart;
import com.jl.service.IDamagePartService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 故障部位表 服务实现类
 * </p>
 *
 * @author JiangJian
 * @since 2019-04-30
 */
@Service
public class DamagePartServiceImpl extends ServiceImpl<DamagePartMapper, DamagePart> implements IDamagePartService {


    @Override
    public void getRepeatDamagePart(PageDataInfo<Map<String, Object>> pageDataInfo, String startTime, String endTime) {
        List<Map<String, Object>> maps = baseMapper.selectDuplicateFaultDevicePart(startTime,endTime);
        pageDataInfo.setCurrent(Constants.FIRST_PAGE);
        pageDataInfo.setSize(maps.size());
        pageDataInfo.setTotal(maps.size());
        pageDataInfo.setRecords(maps);
    }


    /*******************************************************************************************/

    @Override
    public void getTopDamagePartCount(PageDataInfo<Map<String, Object>> pageDataInfo, Integer type, String startTime, String endTime) {
        List<Map<String, Object>> mapList = new ArrayList<>();
        if(Constants.DEVICE_RUN_STATUS_WEEK_TYPE.equals(type)){
//            周
            mapList = baseMapper.selectTopDamagePartCount(type, startTime, null);
        }else if(Constants.DEVICE_RUN_STATUS_MONTH_TYPE.equals(type)){
//            月
            mapList = baseMapper.selectTopDamagePartCount(type, startTime, endTime);
        }
        pageDataInfo.setTotal(mapList.size());
        pageDataInfo.setRecords(mapList);
    }

}
